// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require("base");
	var dialog = require("dialog");
	var constant = require("constant");
	var router = require("../hash/pageRouter");
	var databind = require("databind");
	var valuationCal = require("valuationCal");
	var tools = require("tools");
	var css_plenishConfirmDetail = require("./replenishConfirmDetail.css");
	var creditId;
	var pageIndex = 1,
		pageSize = 5,
		totalPageCount = 1,
		totalRecordCount = 0; //分页初始化
	var init = function(page) {
		creditId = page.params.creditId;
		inquireFinanceReplenishDetail();
		$("#pincupCOnsentPickupId").val(creditId);
		initEvent();
		router.init();

	};
	var initEvent = function() {
		//若未登录，则返回登陆页面
		if (base.getData("sid") == null || base.getData("sid") == "" || base.getData("sid") == undefined) {
			top.location.href = "../login/login.html";
		}
	};

	var inquireFinanceReplenishDetail = function() {
		base.fnAjax({
			action: "inquireFinanceReplenishDetail.json",
			oData: {
				creditId: creditId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {

					juicer.register("getValueByKey", constant.getValueByKey);

					var tpl = $("#pickupConsentBulkstockTpl").html();
					var html = juicer(tpl, data);
					$("#pickupConsentBulkstockBody").html(html);
					
					var tpl3 = $("#exchangeBulkstockInfoTpl1").html();
					var html3 = juicer(tpl3, data);
					$("#exchangeBulkstockInfoBody1").html(html3);

					//重新估值
					$(".valuationLink").unbind("click").click(function(){
						valuationCal.showCal("重新估值", $(this).attr("bulkstockInfoId"), "重量", $(this).attr("weight"), $(this).parent().find(".evaluatePrice"), $(this).parent().find("input[name=evaluatePrice]"), 1);
					});
					
					$("#pickupConsentBtn").unbind("click").click(function() {
					databind.submitDom($("#replenishConfirmDetail"), function() {
						base.alert(1, "确认成功！");
						location.href = "../financing/replenishConfirm.html";
					});
				});
				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});
	};

	return {
		init: init
	};
});